package roleEditor.common
{
	import asset.roleEditor.screenMessageAsset;
	
	import flash.display.Stage;
	import flash.events.Event;

	public class ScreenMessage extends screenMessageAsset
	{
		private var _stage:Stage;
		private var _msg:String;
		
		public function ScreenMessage()
		{
		}
		
		private static var _instance:ScreenMessage;
		public static function get Instance() : ScreenMessage
		{
			if(_instance == null)
			{
				_instance = new ScreenMessage();
			}
			return _instance;
		}

		private function onEnterFrame(evt:Event):void
		{
			if(currentFrame>=totalFrames)
			{
				removeEventListener(Event.ENTER_FRAME, onEnterFrame);
				if(parent) parent.removeChild(this);
			}
		}
		
		public function register(stage:Stage):void
		{
			_stage=stage;
		}
		
		public function get msg():String
		{
			return _msg;
		}

		public function set msg(value:String):void
		{
			_msg = value;
			mcMsg.txtMsg.text=_msg;
			x=(_stage.stageWidth-width)/2;
			y=(_stage.stageHeight-height)/2;
			_stage.addChild(this);
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
			gotoAndPlay(1);
		}
		
		public function dispose():void
		{
			removeEventListener(Event.ENTER_FRAME, onEnterFrame);
		}
	}
}